#import "file_item.h"


@implementation FileItem

- (id) init {
	self = [super init];
	if (self != nil) {
		saved = NO;
	}
	return self;
}

- (id)initFromPath:(NSURL*)fileUrl
		   isSaved:(BOOL)savedState {
	self = [super init];
	if (self != nil) {
		saved = savedState;
		[self setPath:[fileUrl path]];
		[self setDisplay:[fileUrl lastPathComponent]];
	}
	return self;
}

- (id)initFromExisting:(FileItem*)fileItem {
	self = [super init];
	if (self != nil) {
		[self setSaved:[fileItem saved]];
		[self setPath:[fileItem path]];
		[self setDisplay:[fileItem display]];
	}
	return self;
}

- (BOOL)writeToFile:(NSError**)anError {
	[[NSException exceptionWithName:@"NotImplementedException" 
							 reason:@"writeToFile must be implemented by subclasses"
						   userInfo:nil] raise];
	return NO;
}

- (BOOL)readFromFile:(NSError**)anError {
	[[NSException exceptionWithName:@"NotImplementedException" 
							 reason:@"readFromFile must be implemented by subclasses"
						   userInfo:nil] raise];	
	return NO;
}

+ (NSError*) errorWithDescription:(NSString*)description
						errorCode:(int)eCode
						 filePath:(NSString*)aFilePath {
	
	/* Make and return custom domain error. */
	NSArray *objArray = [NSArray arrayWithObjects:description, aFilePath, nil];
	NSArray *keyArray = [NSArray arrayWithObjects:NSLocalizedDescriptionKey,
						 NSFilePathErrorKey, nil];
	NSDictionary *eDict = [NSDictionary dictionaryWithObjects:objArray
													  forKeys:keyArray];
	NSError* err = [[[NSError alloc] initWithDomain:@"SoundBrushError"
											  code:eCode
										  userInfo:eDict] autorelease];
	return err;
}


@synthesize path;
@synthesize display;
@synthesize saved;

@end
